package com.zdxlz.fcmp.business.controller.local;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdxlz.fcmp.business.dto.IpsecVpnTemplateConfigDto;
import com.zdxlz.fcmp.business.entity.IpsecVpnTemplateConfigEntity;
import com.zdxlz.fcmp.business.service.IIpsecVpnTemplateConfigService;
import com.zdxlz.fcmp.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import static com.zdxlz.fcmp.common.core.constant.CommonConstants.*;

/**
 * <p>
 * IPSec模板配置表  前端控制器
 * </p>
 *
 * @author: aman
 * @since 2025-02-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1/ipsec/template")
public class IpsecVpnTemplateConfigController {
    private IIpsecVpnTemplateConfigService IIpsecVpnTemplateConfigService;

    /**
     * @description 分页查询VPN模板信息列表
     * @author aman
     * @date 2025/2/11 16:25
     */
    @GetMapping
    public R getList(@ParameterObject Page<IpsecVpnTemplateConfigEntity> page, @ParameterObject IpsecVpnTemplateConfigDto vpnTemplateConfigDto) {
        return R.ok(IIpsecVpnTemplateConfigService.getList(page, vpnTemplateConfigDto), OPERATION_SUCCESS);
    }

    /**
     * @description 查询所有VPN模板信息列表
     * @author aman
     * @date 2025/2/11 16:25
     */
    @GetMapping("/all")
    public R getAllList() {
        return R.ok(IIpsecVpnTemplateConfigService.getAllList(), OPERATION_SUCCESS);
    }

    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        return R.ok(IIpsecVpnTemplateConfigService.getById(id));
    }

    @PostMapping
    public R create(@RequestBody @Validated IpsecVpnTemplateConfigEntity entity) {
        return R.ok(IIpsecVpnTemplateConfigService.createIpsecVpnTemplateConfig(entity), CREATE_SUCCESS);
    }

    @PutMapping("/{id}")
    public R update(@PathVariable Integer id, @RequestBody @Validated IpsecVpnTemplateConfigEntity entity) {
        entity.setId(id);
        return R.ok(IIpsecVpnTemplateConfigService.updateIpsecVpnTemplateConfig(entity), UPDATE_SUCCESS);
    }

    @DeleteMapping
    public R delete(@RequestBody List<Integer> ids) {
        return R.ok(IIpsecVpnTemplateConfigService.deleteIpsecVpnTemplateConfig(ids), DELETE_SUCCESS);
    }

}
